## -*- coding: utf-8 -*-

#   Copyright (C) 2007, 2008 Yves Junqueira (yves@cetico.org) 
#
#    This file is part of GeekDNS.
#
#    GeekDNS is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    GeekDNS is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with GeekDNS.  If not, see <http://www.gnu.org/licenses/>.

"""Billing and money-related functions.
"""

from datetime import datetime, timedelta

def month_perc_bill(amount):
  # based on
  # http://mail.python.org/pipermail/python-list/2005-October/347167.html
  today = datetime.today()
  oneday = timedelta(days=1)
  q, r = divmod(today.month, 12)
  eom = datetime(today.year+q, r+1, 1) - oneday
  offset = float(today.day) / float(eom.day)
  perc = 1 - offset 
  return float(amount) * float(perc)

